#ifndef __FLASH_H__
#define __FLASH_H__
#include "type.h"


#define BOOT_START_ADDRESS      0x08000000U
#define BOOT_END_ADDRESS        0x08005000U
#define BOOT_SIZE  BOOT_END_ADDRESS - BOOT_START_ADDRESS

#define SETTINGS_START_ADDRESS  0x08005000U
#define SETTINGS_END_ADDRESS    0x08007000U
#define SETTINGS_SIZE SETTINGS_END_ADDRESS - SETTINGS_START_ADDRESS


#define APP_START_ADDRESS       0x08007000U
#define APP_END_ADDRESS         0x08013000U
#define APP_SIZE  APP_END_ADDRESS - APP_START_ADDRESS

#define DOWNLOAD_START_ADDRESS  0x08013800
#define DOWNLOAD_END_ADDRESS    0x0801F800
#define DOWNLOAD_SIZE DOWNLOAD_END_ADDRESS - DOWNLOAD_START_ADDRESS


/* FLASH大小 : 256K */
#define GD32_FLASH_SIZE         0x00040000UL
/* FLASH起始地址 */
#define GD32_FLASH_BASE         0x08000000UL
/* FLASH结束地址 */
#define GD32_FLASH_END          (GD32_FLASH_BASE | STM32_FLASH_SIZE)

#define FLASH_PAGE_SIZE          ((uint32_t)0x800)

#define STM32_FLASH_PAGE_NUM     (GD32_FLASH_SIZE / FLASH_PAGE_SIZE)


MI_BOOL gd32_flash_erase(MI_U32 start_addr, MI_U32 end_addr);
MI_BOOL gd32_flash_write(MI_U32 dest_addr, MI_U8 *src, MI_U32 Len);
MI_BOOL gd32_flash_read(MI_U32 dest_addr, MI_U8* buff, MI_U32 Len);
MI_BOOL copy_download_to_app(void);
#endif //__FLASH_H__